package editor;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;

import model.Square;
import model.SquareType;
import ui.ContainerView;
import ui.Window;
import view.Map;
import view.SquareRep;
import control.Game;

/**
 * Sets up and creates an Editor.
 */
public class Editor implements MouseListener{
	
	private final ContainerView container;
	private final Window w;
	private static Square SELECTED;
	
	/**
	 * Editor constructor
	 */
	public Editor(){
		w = Window.getInstance();
		container = new ContainerView();
		container.setLayout(new BorderLayout());
		w.add(container);
		w.setVisible(true);
		final SquareRep[][] squareRep = new SquareRep[Game.WIDTH][Game.HEIGHT];
		final Square[][] squares = new Square[Game.WIDTH][Game.HEIGHT];
		for(int j = 0;j<squares[0].length;j++){
			for(int i = 0;i<squares.length;i++){
				squares[i][j] = new Square(new SquareType(new Color((5*i+j)%250,(i+5*j)%250,(i+j)%250),"random",false,false));
				squareRep[i][j] = new SquareRep(squares[i][j]);
				squareRep[i][j].addMouseListener(this);
			}
		}
		final Map region = new Map(squareRep);
		container.setMap(region);
	}
	
	public static void main(String[] e){
		new Editor();
	}

	public void mouseClicked(MouseEvent arg0) {
	}

	public void mouseEntered(MouseEvent arg0) {
	}
	public void mouseExited(MouseEvent arg0) {
	}
	public void mousePressed(MouseEvent e) {
		SELECTED = ((SquareRep)e.getSource()).getSquare();
		w.setCursor(SELECTED.getIcon().getImage());
	}
	public void mouseReleased(MouseEvent arg0) {
	}

}
